import { getBaseCategoryList,getBannerList, getFloorList } from "@/api";

//Home的小仓库

//每个小仓库都要有这四个属性
const state = {
    // 分类数据
    categoryList:[],
    // 轮播图数据
    bannerList:[],
    // floor数据
    floorList:[]
};
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList;
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLST(state, floorList) {
    state.floorList = floorList
  }
};
const actions = {
  //通过Api里面的接口函数调用，向服务器发请求，获取服务器数据
  async categoryList({ commit }) {
    let result = await getBaseCategoryList(); //await和async缺一不可
    if (result.code == 200) {
      commit("CATEGORYLIST", result.data);
    }
  },
  // 获取首页轮播图数据
  async getBannerList({ commit }){
    let result = await getBannerList()
    if(result.code == 200){
      commit("GETBANNERLIST",result.data)
    }
  },
  // 获取首页floor数据
  async getFloorList({commit}){
    let result = await getFloorList()
    if(result.code == 200){
      commit("GETFLOORLST",result.data)
    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
